package com.xiaochao.yang.nfc.card;

import android.app.Activity;
import android.content.Context;
import android.media.Image;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;


import java.util.List;
import java.util.zip.DeflaterInputStream;

public class CustomListAdapter extends BaseAdapter {
    private Activity activity;
    private LayoutInflater inflater;
    private List<Device> deviceItems;

    public CustomListAdapter(Activity activity, List<Device> deviceItems) {
        this.activity = activity;
        this.deviceItems = deviceItems;
    }

    public int getCount() {
        return deviceItems.size();
    }

    public Object getItem(int i) {
        return deviceItems.get(i);
    }

    public long getItemId(int i) {
        return i;
    }

    public View getView(int i, View view, ViewGroup viewGroup) {
        if(inflater == null)
            inflater = (LayoutInflater)activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        if(view == null)
            view = inflater.inflate(R.layout.list_row, null);

        ImageView thumbnail = (ImageView)view.findViewById(R.id.thumbnail);
        TextView device = (TextView)view.findViewById(R.id.device);
        TextView dv_status = (TextView)view.findViewById(R.id.dv_status);

        Device d = deviceItems.get(i);
        // Test
        thumbnail.setImageResource(d.getDevicePic());
        device.setText(d.getDeviceName());
        dv_status.setText(d.getDeviceStatus());

        return view;
    }
}
